<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
  layer.photos({
    photos: ".layer-photos-demo",
    anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });
  function open_add(title, url) {
    if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
      layer.open({
        type: 2,
        title: title,
        content: url,
        area: ["95%", "95%"],
        maxmin: true,
      });
    } else {
      layer.open({
        type: 2,
        title: title,
        content: url,
        area: ["70%", "95%"],
        maxmin: true,
      });
    }
  }
  /*数据-删除*/
  function open_dels(obj, url, id) {
    var ids = [id];
    layer.confirm("确认要执行该操作吗？", function (index) {
      //发异步删除数据
      $.post(
        url,
        { id: ids },
        function (data) {
          if (data.status == 0) {
            $(obj).parents("tr").remove();
            $("#count").text($("#count").text() - 1);
            layer.msg(data.msg, { icon: 1, time: 1000 });
          } else {
            layer.msg(data.msg, { icon: 2, time: 1000 });
          }
        },
        "json"
      );
    });
  }
  function delAll(url) {
    var ids = [];
    // 获取选中的id 
    $('tbody input').each(function (index, el) {
      if ($(this).prop('checked')) {
        ids.push($(this).val())
      }
    });
    if (ids.length <= 0) {
      layer.msg('请选择删除选项', { icon: 2, time: 1000 });
      return true;
    }
    layer.confirm('确认要删除吗？', function (index) {
      //捉到所有被选中的，发异步进行删除
      $.post(url, { id: ids },
        function (data) {
          if (data.status == 0) {
            layer.msg(data.msg, { icon: 1, time: 1000 }, function () {
              // 获得frame索引
              location.reload();
              layer.close(index);
            });
          } else {
            layer.msg(data.msg, { icon: 2, time: 1000 });
          }
        }, "json"
      );
      // $(".layui-form-checked").not('.header').parents('tr').remove();
    });
  }
</script>